cd E:\data\合作研究\房价\房价和健康数据\最终使用数据

use cgss_health,clear


*****add the label ***************
gen gender=0
replace gender=0 if female==0
replace gender=1 if female==1
replace gender=. if female==.
label var gender  "性别"
replace work_status=3 if work_status==0
replace work_status=0 if work_status==2
replace work_status=3 if work_status==1
egen  code_province=group(province)
gen houseprices=-houseprice

***set the label of the variables***
label var comercial1 "Comercial house prices"
label var average_rate "Average growth rate of house prices"
label var air_quality "PM2.5"
label var revenue "Individual income"
label var Han "Ethnicity (Han=1, otherwise=0)"
label var nomarriage "Marriage status (Non marriage=1, otherwise=0)"
label var education "Year of education"
label var work_status "Work status(Non work =1, otherwise=1)"
label var a68a "Number of children (under 18 years)"
label var healthcare "medical service"
label var familyrevenue "Family income"
label var health "Indvidual physical health"
label var houseprice "House prices"
label var BMI2 "BMI"
label var excise "Physical exercise"
label var mental_health "Mental health"
label var land "Land supply"
label var gdp "The real GDP per capita"
label var age "Age"
label var nomarriage "Marriage status (Non marriage=1, otherwise=0)"
label var gender "Gender (female=1, male=0)"
label var urban "Residential status (living in urban area= 1, otherwise = 0)"

global var " revenue age   gender urban Han nomarriage education work_status a68a familyrevenue   air_quality healthcare"
*******data description****
sum  health houseprice mental_health excise  $var BMI2 comercial1 average_rate land gdp
des   health houseprice mental_health excise  $var BMI2 comercial1 average_rate land gdp

******test**
collin houseprice revenue age   gender urban Han nomarriage education work_status a68a familyrevenue   air_quality healthcare
des houseprice revenue age   gender urban Han nomarriage education work_status a68a familyrevenue   air_quality healthcare

******regression
reg health houseprice $var
est store reg1
reg health houseprice $var i.code_province
est store reg2
reg health houseprice $var i.Year i.code_province
est store reg3
reg health c.houseprice##c.houseprice $var i.Year 
est store reg4
ologit health houseprice $var i.Year i.code_province
est store reg5


esttab  reg1 reg2 reg3 reg4 reg5, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(40)    varlabels(_cons Constant) mtitles("OLS" "OLS"  "OLS" "OLS"  "OLogit") ///
keep(houseprice c.houseprice#c.houseprice $var _cons) /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/




reg health c.houseprice##c.houseprice $var i.Year i.code_province
margins, at(houseprice=(0.3(0.2)2.2)) atmeans 
marginsplot,ylab(3(0.5)4.5) ylabel(, nogrid)

*****mediation mechanism
ologit excise houseprice  $var  i.Year i.code_province
est store reg1
ologit mental_health houseprice  $var  i.Year i.code_province
 est store reg2

 ologit health  excise houseprice mental_health   $var  i.Year i.code_province
 est store reg3
 esttab  reg1 reg2  reg3 , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(50)    varlabels(_cons constant) mtitles("OLS" "OLS"  "OLS" "OLS"  "OLogit") ///
keep(houseprice excise  mental_health  revenue age   gender urban Han nomarriage education work_status a68a familyrevenue   air_quality healthcare _cons ) /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/
 

****Cross-analysis between gender and physical health
global var1 " revenue age hukou   urban Han nomarriage education work_status a68a familyrevenue   air_quality healthcare"
gen house_gender=-houseprice*gender

 ologit health   houseprice    $var  i.Year i.code_province if gender==0
 est store reg1
  ologit health   houseprice    $var  i.Year i.code_province if gender==1
 est store reg2
  ologit health   houseprice  house_gender  $var  i.Year i.code_province 
 est store reg3
 esttab  reg1 reg2  reg3 , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(30)    varlabels(_cons constant) mtitles("OLS" "OLS"  "OLS" "OLS"  "OLogit") ///
keep(houseprice    house_gender revenue age   gender urban Han nomarriage education work_status a68a familyrevenue   air_quality healthcare ) ///  
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/

************Cross-analysis between number of house and physical health

ologit health houseprices  $var  i.Year i.code_province if a65==0
 est store reg1
ologit health houseprice  $var  i.Year i.code_province if a65==1
 est store reg2
ologit health houseprice  $var  i.Year i.code_province if a65>1
 est store reg3
 esttab  reg1 reg2  reg3 , cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(30)    varlabels(_cons constant) mtitles("OLS" "OLS"  "OLS" "OLS"  "OLogit") ///
keep(houseprice   houseprices  revenue age   gender urban Han nomarriage education work_status a68a familyrevenue   air_quality healthcare ) ///  
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/
********robust


ologit health comercial1  $var  i.Year i.code_province
est store reg1
ologit health average_rate $var i.Year i.code_province
est store reg2
ologit BMI2  houseprice $var  i.Year i.code_province
est store reg3
ologit BMI2  comercial1 $var  i.Year i.code_province
est store reg4
ologit BMI2  average_rate $var  i.Year i.code_province
est store reg5
ivreg health (houseprice=land gdp)  $var  
est store reg6
overid
ivendog
esttab reg3 reg4 reg5  reg1 reg2  reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
legend label varwidth(30)    varlabels(_cons constant) mtitles("BMI" "BMI"  "BMI" "Physical Health"  "Physical Health" "Physical Health") ///
keep(houseprice comercial1 average_rate revenue age   gender urban Han nomarriage education work_status a68a familyrevenue   air_quality healthcare _cons) /// 
stats(N r2, fmt(0 3) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01) /*table 3*/


